//
//  TabBarController.m
//  TeamWork
//
//  Created by lanou3g on 15/11/17.
//  Copyright © 2015年 Project. All rights reserved.
//

#import "TabBarController.h"
#import "ChatViewController.h"
#import "ContactViewController.h"
#import "FindViewController.h"
#import "UserViewController.h"
#import "TableViewController.h"
@interface TabBarController ()

@end

@implementation TabBarController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    // 添加所有子控制器
    [self setUpAllChildViewController];
   
}

/**
 *  添加所有的子控制器
 */
- (void) setUpAllChildViewController
{
    // 聊天页面
    // 实例化ChatViewController类实体
    ChatViewController *chatVC = [[ChatViewController alloc] init];
    
    // 创建导航栏控制器，并且设置子控制器
    UINavigationController *chatNC = [[UINavigationController alloc] initWithRootViewController:chatVC];
    
    
    // 设置子控制器属性
    [self setUpChindViewController:chatNC image:[UIImage imageNamed:@"chat"] title:@"聊天"];
    
    
    
    // 通讯录
    // 实例化ContactViewController类实体
    ContactViewController *contactVC = [[ContactViewController alloc] init];
    
    // 创建导航栏控制器，并且设置子控制器
    UINavigationController *contactNC = [[UINavigationController alloc] initWithRootViewController:contactVC];
    
    // 设置子控制器属性
    [self setUpChindViewController:contactNC image:[UIImage imageNamed:@"contact"] title:@"通讯录"];

    
    
    // 查找
    // 实例化FindViewController类实体
    FindViewController *findVC = [[FindViewController alloc] init];
    
    // 创建导航栏控制器，并且设置子控制器
    UINavigationController *findNC = [[UINavigationController alloc] initWithRootViewController:findVC];
    
    // 设置子控制器属性
    [self setUpChindViewController:findNC image:[UIImage imageNamed:@"find"] title:@"发现"];
    
    
    
    //娱乐页面
    TableViewController *recreationVC = [[TableViewController alloc] init];
    UINavigationController *recreationNC = [[UINavigationController alloc] initWithRootViewController:recreationVC];
    recreationNC.navigationBar.backgroundColor =[UIColor  blackColor];
    //设置子视图控制器
    [self setUpChindViewController:recreationNC image:[UIImage imageNamed:@"yule"] title:@"娱乐"];
    
    

    
    // 用户
    // 实例化UserViewController类实体
    UserViewController *userVC = [[UserViewController alloc] init];
    
    // 创建导航栏控制器，并且设置子控制器
    UINavigationController *userNC = [[UINavigationController alloc] initWithRootViewController:userVC];
    
    // 设置子控制器属性
    [self setUpChindViewController:userNC image:[UIImage imageNamed:@"user"] title:@"我"];

    // 修改选中某个tabbar的时候的图片的颜色
    self.tabBar.tintColor = [UIColor orangeColor];
}

/**
 *  添加一个子控制器
 *
 *  @param VC    视图
 *  @param image tabBar显示的图片
 *  @param title 标题
 */
- (void) setUpChindViewController:(UIViewController *) VC image:(UIImage *) image title:(NSString *) title
{
    // 标题
    VC.tabBarItem.title = title;
    
    // tabBar显示的图片
    VC.tabBarItem.image = image;
    
    // 右上角红圈显示的内容
    VC.tabBarItem.badgeValue = @"10";

    // 实例化一个字典
    NSMutableDictionary *typeDic = [NSMutableDictionary new];
    
    // 为字典添加内容为文字颜色
    typeDic[NSForegroundColorAttributeName] = [UIColor orangeColor];
    
    // 为字典添加内容为文字字体
    typeDic[NSFontAttributeName] = [UIFont boldSystemFontOfSize:17];
    
    // 将字典的内容赋予tabBar
    [VC.tabBarItem setTitleTextAttributes:typeDic forState:UIControlStateSelected];
    

    // 添加子视图到控制器内
    [self addChildViewController:VC];
}



















- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
